from digits import isPandigital

pandigitalProducts = set()

for a in xrange(1, 10):
    for b in xrange(1234, 9877):
        if isPandigital3(a, b, a*b):
            print a,b,a*b
            pandigitalProducts.add(a*b)

for a in xrange(12, 98):
    for b in xrange(123, 10000/a):
        if isPandigital3(a, b, a*b):
            print a,b,a*b
            pandigitalProducts.add(a*b)
            
print sum(pandigitalProducts)
